const {exec}=require("../db")

class Goods{
    async queryAll(req,res){
        let sql=`SELECT * FROM goods`;
        const menu=[
            {
                title: '高效轻薄本',
                c: [
                    { img: './img/goods/menu/m1.1.png', name: '高性能轻薄本', list: ['无畏Pro15', '无畏Pro16', '灵耀Pro', '灵耀X双屏Pro', '灵耀X Fold'] },
                    { img: './img/goods/menu/m1.2.png', name: '便携轻薄本', list: ['无畏15', '无双', '灵耀X13', '灵耀14', 'a豆14Pro', '无畏14'] },
                    { img: './img/goods/menu/m1.3.jpg', name: '无畏', list: ['无畏14', '无畏15', '无畏160', '无畏Pro15', '无畏Pro16', '无畏变形本',] },
                    { img: './img/goods/menu/m1.4.png', name: 'a豆', list: ['a豆14', 'a豆14Pro', 'a豆平板'] },
                    { img: './img/goods/menu/m1.5.png', name: '灵耀新品', list: ['灵耀14', '灵耀X13', '灵耀X14', '灵耀Pro', '灵耀X双屏', '灵耀X Fold',] },
                    { img: './img/goods/menu/m1.6.jpg', name: '破晓', list: ['破晓2', '破晓Pro', '破晓Air'] },
                    { img: './img/goods/menu/m1.7.jpg', name: 'a豆智能', list: ['平板', 'a豆键鼠', '智能', '充电器', '扩展坞'] },
                ]
            }, {
                title: '游戏本送豪礼',
                c: [
                    { img: './img/goods/menu/m2.1.png', name: '天选系列', list: ['天选3'] },
                    { img: './img/goods/menu/m2.2.jpg', name: '天选家族', list: ['鼠标外设', '鼠标垫', '抱枕'] },
                ]
            }, {
                title: 'ROG',
                c: [
                    { img: './img/goods/menu/m3.1.jpg', name: '魔霸系列', list: ['魔霸新锐', '魔霸6', '魔霸6 Plus'] },
                    { img: './img/goods/menu/m3.2.jpg', name: '枪神系列', list: ['枪神6', '枪神6 Plus', '枪神7', '枪神7 Plus'] },
                    { img: './img/goods/menu/m3.3.jpg', name: '幻系列', list: ['幻16', '幻15', '幻14', '幻13', '幻X', '显卡拓展坞'] },
                    { img: './img/goods/menu/m3.4.jpg', name: 'ROG台式机', list: ['光刃G15', '光魔G35', '光魔G15', '光魔G10', '枪神X'] },
                    { img: './img/goods/menu/m3.5.jpg', name: 'ROG手机', list: ['ROG游戏手机6', 'ROG6 天机系列'] },
                    { img: './img/goods/menu/m3.6.jpg', name: '冰刃系列', list: ['冰刃6 双屏',] },
                    { img: './img/goods/menu/m3.7.png', name: '外设产品', list: ['鼠标', '键盘', '耳机', '鼠标垫', '路由器'] },
                ]
            }, {
                title: 'ProArt',
                c: [
                    { img: './img/goods/menu/m4.1.png', name: '笔记本', list: ['创16'] },
                    { img: './img/goods/menu/m4.2.jpg', name: '显示器', list: ['ProArt显示器'] },
                    { img: './img/goods/menu/m4.3.jpg', name: '主板', list: ['ProArt主板'] },
                ]
            }, {
                title: '台式机',
                c: [
                    { img: './img/goods/menu/m5.1.png', name: '台式机', list: ['天选X', '破晓X', '碉堡选配机'] },
                    { img: './img/goods/menu/m5.2.png', name: 'ROG台式机', list: ['枪神X', '光刃G15', '光魔G35', '光魔G15', '光魔G10'] },
                    { img: './img/goods/menu/m5.3.jpg', name: 'Mini Pc', list: ['PN系列', 'PB系列', 'a豆系列'] },
                    { img: './img/goods/menu/m5.4.jpg', name: '一体机', list: ['猎鹰A5', '猎鹰M3', '猎鹰V4'] },
                    { img: './img/goods/menu/m5.5.jpg', name: '显示器', list: ['22-25英寸', '26-28英寸', '29-65英寸'] },
                    { img: './img/goods/menu/m5.6.png', name: '外设产品', list: ['鼠标', '键盘', '耳机'] },

                ]
            }, {
                title: '电脑组件',
                c: [
                    { img: './img/goods/menu/m6.1.jpg', name: '主板', list: ['Z790系列', 'X670E/B650', 'Z690系列', 'B660系列', 'X570/B550'] },
                    { img: './img/goods/menu/m6.2.png', name: '显卡', list: ['ROG系列', 'TUF系列', 'DUAL系列', '巨齿鲨系列', '套装系列'] },
                    { img: './img/goods/menu/m6.3.jpg', name: '显示器', list: ['22-25英寸', '26-28英寸', '29-65英寸'] },
                    { img: './img/goods/menu/m6.4.png', name: '机电散', list: ['机箱', '电源', '散热器'] },
                    { img: './img/goods/menu/m6.5.jpg', name: 'DIY套装系列', list: ['板U套装', '板卡套装', '全家桶套装', '机电散热套装', '键鼠套装'] },
                ]
            }, {
                title: '网络/外设/周边',
                c: [
                    { img: './img/goods/menu/m7.1.png', name: '路由器', list: ['家用路由器', '电竞路由器', '分布式路由器'] },
                    { img: './img/goods/menu/m7.2.jpg', name: '键鼠外设', list: ['天选键盘', 'a豆键盘', '键盘', '鼠标', '耳机', '家用办公'] },
                    { img: './img/goods/menu/m7.3.jpg', name: '周边', list: ['ROG周边', '天选周边', 'a豆周边', '外设周边', '智能周边'] },
                    { img: './img/goods/menu/m7.4.jpg', name: '权益/服务', list: ['延长保修', '服务升级', '新人礼', '福袋', '黑金会员'] },
                    { img: './img/goods/menu/m7.5.png', name: '华硕良品', list: ['笔记本'] },
                ]
            }
        ];
        try {
            let results=await exec(sql)
            res.json({msg:'查询成功',data:{list:results,menu},code:200})
        } catch (error) {
            res.json({msg:"获取数据失败",code:300})
        }
    }
    async query(req,res){
        let {gid}=req.query
        let sql=`SELECT * FROM goods where gid=?`;
        let sql1=`SELECT tag1,tag2,tag3,tag4,tag5,tag6,tag7,tag8,tag9,tag10,tag11,tag12 FROM goods_info where gid=?`;
        let sql2=`SELECT * FROM goods WHERE kind=?`
        let params=[gid];
        try {
            let results=await exec(sql,params)
            let data1=await exec(sql1,params)
            if(results.length>=1){
                const data2=await exec(sql2,[results[0].kind])
                let nav_mini=[
                    './img/goods/m1-box2-1.png',
                    './img/goods/m1-box2-2.png',
                    './img/goods/m1-box2-3.png',
                    './img/goods/m1-box2-4.png',
                    './img/goods/m1-box2-5.png',
                ];
                let swiper=[
                    './img/goods/lunbo/1.jpg',
                    './img/goods/lunbo/2.jpg',
                    './img/goods/lunbo/3.jpg',
                    './img/goods/lunbo/4.jpg',
                    './img/goods/lunbo/5.jpg',
                    './img/goods/lunbo/6.jpg',
                    './img/goods/lunbo/7.jpg',
                    './img/goods/lunbo/8.jpg'
                ]
                res.json({
                    msg:'查询成功',
                    info:{...results[0],
                        att:data1[0]},
                        recom:data2,
                        nav_mini,
                        swiper,
                        code:200})
            }else{
                res.json({msg:'未找到结果',code:404})
            }
        } catch (error) {
            res.json({msg:"获取数据失败",code:300})
        }
    }
}

module.exports=new Goods